#-*- coding:utf-8 -*-
# @Author : yushen

import requests
from tests.sfl_testcase.Public_methods.common_sfl_header_model import Headers
import pprint
from tests.sfl_testcase.sfl_conf.sfl_conf import *

class Performpage(Headers):

    def getAllCommunity(self):#V3.10.4获取主页帖子
        url = '{}/sephora-terminal-shopping/api/community/getAllCommunity'.format(sfl_host_224)
        data = {'currentPage':1}
        r = requests.post(url,headers=self.headers_224(),json=data)
        # pprint.pprint(r.json)
        return r.json()

    def getCommunityAllComments(self):#帖子全部评论
        url = '{}/sephora-terminal-shopping/api/community/getCommunityAllComments'.format(sfl_host_224)
        data = {"postId": "100de5d0-be78-11e9-9ab2-51d821b0dcfb"}
        r = requests.post(url,headers=self.headers_224(),json=data)
        # pprint.pprint(r.json())
        return r.json()

    def getProductListDetail(self):#获取多个商品详情
        url = '{}/sephora-terminal-shopping/api/goods/getProductListDetail'.format(sfl_host_224)
        data = {
              "goodSkuIds": [
                {
                  "productId": "985412",
                  "skuId": "12012175"
                },
                {
                  "productId": "985412",
                  "skuId": "12012175"
                }
              ]
            }
        r = requests.post(url,headers=self.headers_224(),json=data)
        # pprint.pprint(r.json())
        return r.json()

    def Commoditysearch(self):  # 商品搜索
        url = '{}/sephora-terminal-shopping/api/goods/getProductByKeyWords'.format(sfl_host_224)
        data = {
              "keyWords": "迪奥",
              "pageSize": 20,
              "currentPage": "1"
            }
        r = requests.post(url,headers=self.headers_224(),json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def shopcart_getShopCartInfo(self): #获取购物车商品信息
        url = '{}/sephora-terminal-shopping/api/shopcart/getShopCartInfo'.format(sfl_host_224)
        data = {}
        r = requests.post(url,headers=self.headers_224(),json=data)
        print(r.headers)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def getScreenTips(self):#获取提示语
        data = {"pageSize":3}
        headers = {'Content-Type': 'application/json',
                   'macValue': 'cc:4b:73:6f:9a:9a'},
        r = requests.get('{}/sephora-terminal-shopping/api/screen/getScreenTips'.format(sfl_host_224),headers =headers,params=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def getHotCommunity(self):#获取热门帖子
        url = '{}/sephora-terminal-shopping/api/community/getHotCommunity'.format(sfl_host_224)
        data = {"hotTopicName": "dolore"}
        r = requests.post(url,headers=self.headers_224(),json=data)
        # pprint.pprint(r.json())
        return r.json()

    def getCommunityComments(self):#帖子评论
        url = '{}/sephora-terminal-shopping/api/community/getCommunityComments'
        data = {"postId": "100de5d0-be78-11e9-9ab2-51d821b0dcfb"}
        r = requests.post(url.format(sfl_host_224),headers=self.headers_224(),json=data)
        # pprint.pprint(r.json())
        return r.json()

    def getCommunityDetail(self):#获取帖子详情
        url = '{}/sephora-terminal-shopping/api/community/getCommunityDetail'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'terminalCode':'RYAM02019082700',
                  'mallId':'5be53145b80a81146db071e2',
                  'Content-Type':'application/json; charset=utf-8'}
        data = {"openId":"qVH21ZXQnGLE6v01","postId":"f576a370-1a6a-11ea-84d7-07c9c85c52e5","type":"NINE_BLOCK"}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json())
        return r.json()

    def goods_getCommunityDetail(self):#获取多个商品详情
        url = '{}/sephora-terminal-shopping/api/goods/getProductDetail'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'terminalCode':'RYAM02019082700',
                  'mallId':'5be53145b80a81146db071e2',
                  'Content-Type':'application/json; charset=utf-8'}
        data = {"productId":1613}
        r = requests.post(url=url,headers=header,json=data)
        pprint.pprint(r.json(),indent=2)
        return r.json()

    def goods_getProductDetail(self):#获取商品详情
        url = '{}/sephora-terminal-shopping/api/goods/getProductDetail'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'terminalCode':'RYAM02019082700',
                  'Content-Type':'application/json; charset=utf-8'}
        data = {"productId":'755501'}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def community_getSephoraCommunity(self):#获取丝芙兰帖子
        url = '{}/sephora-terminal-shopping/api/goods/getProductDetail'.format(sfl_host_v4)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'terminalCode':'RYAM02019082700',
                  'mallId':'5be53145b80a81146db071e2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"currentPage":1}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def goods_allColorProperty(self):#V1.8Mac子弹头色板质地色系
        url = '{}/sephora-terminal-shopping/api/goods/allColorProperty'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'terminalCode':'RYAM02019082700',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"productId":'755501'}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def goods_getConcreteColor(self):#V1.8子弹头色板
        url = '{}/sephora-terminal-shopping/api/goods/getConcreteColor'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'terminalCode':'RYAM02019082700',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"productId":'755501',
                'colorValue':'',
                'colorMaterial':''
                }
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def goods_getProduct(self):#根据分类id获取商品列表
        url = '{}/sephora-terminal-shopping/api/goods/getProduct'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"currentPage":'755501',
                'pageSize':'',
                'categoryId':'148'
                }
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def goods_getSkuSpec(self):#SKU列表
        url = '{}/sephora-terminal-shopping/api/goods/getSkuSpec'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"productId":'1613'}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def goods_getProductByKeyWords(self):#商品搜索
        url = '{}/sephora-terminal-shopping/api/goods/getProductByKeyWords'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"keyWords":'迪奥',
                'pageSize':10,
                'currentPage':1}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def screen_getScreenSaverList(self):
        '''获取屏保信息'''
        url = '{}/sephora-terminal-shopping/api/screen/getScreenSaverList'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {}
        r = requests.post(url=url,headers=header,json=data)
        pprint.pprint(r.json(),indent=2)
        return r.json()

    def news_list(self,currentPage,pageSize):#管理后台-获取新闻列表
        url = '{}/sephora-terminal-shopping/manager/news/list'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"currentPage":currentPage,"pageSize":pageSize,"startAt":"","endAt":"","title":""}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def manager_news_update(self,title,content):#管理后台-修改新闻
        url = '{}/sephora-terminal-shopping/manager/news/update'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"title":title,"id":155,"status":0,"newsDay":"2019-11-21",
                "pics":"http://rongyi.b0.rongyi.com/sephora/1911211446308688.png,http://rongyi.b0.rongyi.com/sephora/2001191110384520.png",
                "content":content}
        r = requests.post(url=url,headers=header,json=data)
        # pprint.pprint(r.json(),indent=2)
        return r.json()

    def managerapi_goods_queryByBarcode(self,barCode):#管理后台-修改新闻
        url = '{}/sephora-terminal-shopping/api/goods/queryByBarcode'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8',
                  'terminalCode':'RYW201503082'}
        data = {"barCode":barCode}
        r = requests.post(url=url,headers=header,json=data)
        pprint.pprint(r.json(),indent=2)
        return r.json()

    def api_goods_getProductDesc(self,productId):
        '''获取BDP页面'''
        url = '{}/sephora-terminal-shopping/api/goods/getProductDesc'.format(sfl_host_224)
        header = {'macValue':'6c:21:a2:c2:b4:b2',
                  'Content-Type':'application/json;charset=utf-8'}
        data = {"productId":productId}
        r = requests.post(url=url,headers=header,json=data)
        pprint.pprint(r.json(),indent=2)
        return r.json()